uint mpi_rank, mpi_ranks,accepts_per_rank; 

struct mpi_progress {
	float *rejection_threshold;
	bool *accepted;
	double elapsed_time, start_time;
	uint n,*rejections,*acceptances;
	float *current_weights,*last_weights;
	struct Rmn *mean, **eigenvectors, *eigenvalues;
};


struct mpi_progress init_mpi_progress (uint n, uint acceptances){
	struct mpi_progress return_data;

	return_data.rejections=new uint[mpi_ranks];	
	return_data.acceptances=new uint[mpi_ranks];
	return_data.n=mpi_ranks;

	return_data.accepted=new bool[acceptances];

	//if (PROPORTION==1)
	for (uint i=0;i<ACCEPTANCES;i++) //lets start off by just accepting the first ACCEPTANCES, not ACCEPTANCES/PROPORTION
		return_data.accepted[i]=1;


	return_data.eigenvectors=new Rmn*[acceptances];

	for (uint i=0;i<acceptances;i++)
		return_data.eigenvectors[i]=init_Rmn(n,n,1);

	return_data.mean=init_Rmn(acceptances,n,1); 

	return_data.eigenvalues=init_Rmn(acceptances,n,0);
	for (uint i=0;i<acceptances;i++)
		return_data.eigenvalues->f[i]=init_eigen_Rn(n);

	return_data.last_weights=new float[(uint)(acceptances/PROPORTION)];
	return_data.current_weights=new float[(uint)(acceptances/PROPORTION)];
	for (uint i=0;i<(uint)(acceptances/PROPORTION);i++)
			return_data.last_weights[i]=1.f/(acceptances);  // normally is 1.f/(ACCEPTANCES), but we want to divide by the largest value in order to reduce time... YES I DO WANT TO DO THAT, BUT NOT NOW

	return_data.rejection_threshold=new float[acceptances];


	//for (uint i=0;i<mpi_ranks;i++) 
	//	for (uint j=0;j<accepts_per_rank;j++) 
	//		return_data.parameters[i*accepts_per_rank+j]=init_Rn_rnd(n);
	return return_data;

}
void print_parameters (struct Rn *parameters, float d, uint rank) {
	                cerr<<"Accepted parameters are: {"<<parameters->f[0];
                for (uint i=1;i<parameters->n;i++)
                        cerr<<","<<parameters->f[i];
                cerr<<"} with d="<<d<<" found by mpi_rank="<<rank<<endl;
}

int check_mpi_progress (struct mpi_progress progress, float elapsed_time, float rejection_threshold, uint rejections) {
	uint sum_rejections=0;//,best_process=-1;
	//float best_rejection_threshold=FLT_MAX;
	for (uint i=0;i<progress.n;i++) {
		sum_rejections+=progress.rejections[i];
		if (elapsed_time>0 && elapsed_time<progress.elapsed_time){ // if more time than allowed has passed...
			if (mpi_rank==0)
				cerr<<"Exceeded predetermined time limit "<<elapsed_time<<"s, quitting"<<endl;
			return -1;
/*		} if (rejection_threshold>0 && progress.rejection_threshold[i]<rejection_threshold) { // if a process has got under the reject threshold
			if (mpi_rank==0) {
				print_parameters(progress.parameters[i], progress.rejection_threshold[i],i); //we need to print this
				cerr<<"Reached predetermined threshold "<<rejection_threshold<<", quitting."<<endl;
			}
			return -1; */
		} if (rejections>0 && sum_rejections>rejections) {
			if (mpi_rank==0)
				cerr<<"Exceeded predetermined number of rejections "<<rejections<<", quittng."<<endl;
			return -1;
		} /*if (progress.rejection_threshold[i]<best_rejection_threshold) {
			best_process=i;
			best_rejection_threshold=progress.rejection_threshold[i];
		} */
	}
return 0;
}
